<?php

$params = require(__DIR__ . '/params.php');  // 引入当前文件夹下的文件

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    // 'defaultRoute' => 'site/login',  //默认路由，配置404为佳
    // 'catchAll' => 'hello/index',     //抓取全部规则，用于临时维护信息为佳
    'components' => [
        'request' => [
            'cookieValidationKey' => '20140319',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        
        'db' => require(__DIR__ . '/db.php'),
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => true,
            'suffix' => '.html',
            'rules' => [
                '' => 'site/index', //首页 index
                // 'catchAll' => ['site/offline'], 拦截路由 维护用
                '<action:([a-zA-Z]\w+)>' => 'site/<action>',  //单页 single
                [ //列表页 二级 带page页数  list
                    'pattern' => 'article/<catSlug:([a-zA-Z]\w*)?>/<page:\d*>',
                    'route' => 'article/index',
                    'defaults' => ['page' => 1,'catSlug'=>null],
                    'suffix' => '',
                ],
                [ //列表页 一级 带page页数  list
                    'pattern' => '<controller:(article)>/<page:\d*>',
                    'route' => '<controller>/index',
                    'defaults' => ['page' => 1],
                    'suffix' => '',
                ],
                [ //内页  content
                    'pattern' => 'article/<catSlug:[a-zA-Z]\w+>/<slug:\S+>',
                    'route' => 'article/content',
                ],
                // [ //后台 admin 带do参数
                //     'pattern' => '<controller:(admin)>-<action:\w+>-<do:\w+>/<page:\d*>',
                //     'route' => '<controller>/<action>',
                //     'defaults' => ['page' => '1'],
                //     'suffix' => '',
                // ],
                [ //普通操作
                    'pattern' => '<controller:\w+>-<action:\w+>',
                    'route' => '<controller>/<action>',
                ],
            ],
        ],
    ],
    'params' => $params,
    // 'bootstrap' => [
    //     'debug','gii'
    // ],
    // 'modules' => [
    //     'debug' => [
    //         'class' => 'yii\debug\Module',
    //     ],
    //     'gii' => [
    //         'class' => 'yii\gii\Module',
    //     ]
    // ]
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
    ];
}

return $config;
